// pages/china/china.js
import * as echarts from '../../ec-canvas/echarts';
const app =getApp()
import geoJson from './chinaMap.js';

function initChartMap(canvas, width, height, dpr) {
  const chart = echarts.init(canvas, null, {
    width: width,
    height: height,
    devicePixelRatio: dpr // new
  });
  canvas.setChart(chart);

  echarts.registerMap('henan', geoJson);


  const option = {
    tooltip: {
      trigger: 'item',
      formatter: '{b}: 确诊{c}'
    },

    visualMap: {
      max: 10000,
      type: 'piecewise',
    },
    toolbox: {
      show: true,
      orient: 'vertical',
      left: 'right',
      top: 'center',
      feature: {
        dataView: { readOnly: false },
        restore: {},
        saveAsImage: {}
      }
    },
    series: [{
      type: 'map',
      mapType: 'henan',
      zoom:1.3,
      label: {
        normal: {
          show: true,
          textStyle:{
            fontsize:12
          }
        },
        emphasis: {
          textStyle: {
            color: '#fff'
          }
        }
      },
      itemStyle: {

        normal: {
          borderColor: '#389BB7',
          areaColor: '#fff',
        },
        emphasis: {
          areaColor: '#389BB7',
          borderWidth: 0
        }
      },
      animation: false,
     data: app.globalData.confirmMap

    }],

  };
  chart.setOption(option);

  return chart;
}
Page({

    /**
     * 页面的初始数据
     */
    data: {
      ec: {
        onInit: null
      },
      ecmap: {
        onInit: initChartMap
      },
        time: 0,
        nowConfirm: 0,
        confirm: 0,
        dead: 0,
        nowSevere: 0,
        suspect: 0,
        noInfect: 0,
        importedCase: 0,
        heal: 0,
        addNowConfirm: 0,
        addConfirm: 0,
        addDead: 0,
        addNowSevere: 0,
        addSuspect:0,
        addNoInfect: 0,
        addImportedCase: 0,
        addHeal: 0,
        datalist:[],
        datalist2:[]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
     this.getDate()
     this.setData({
      ec: {
          onInit: this.initChart
        }

  })
  
    },
    getOptions(xdata, data1,data2) {

      return {
  
        title: {
          text: '新增本土',
          left: '0'
        },
        legend: {
          data: ['确诊人数','死亡人数'],
  
          left: 'center',
        
          z: 100
        },
        grid: {
          containLabel: true
        },
        tooltip: {
          show: true,
          trigger: 'axis'
        },
        // x轴的数据
        xAxis: {
          type: 'category',
          boundaryGap: false,
          // 必须成为参数
          data: xdata,
  
        },
        yAxis: {
          x: 'center',
          type: 'value',
          splitLine: {
            lineStyle: {
              type: 'dashed'
            }
          }
          // show: false
        },
        series: [{
          name: '确诊',
          type: 'line',
          smooth: true,
          data: data1
        },{
          name: '治愈',
          type: 'line',
          smooth: true,
          data: data2
        }
      ],
       
      }
    },
  
    initChart(canvas, width, height, dpr) {
      // 绘制我们图的大小 style ="width ; height"
      const chart = echarts.init(canvas, null, {
        width: width,
        height: height,
  
      });
      canvas.setChart(chart);
      
  
      // this.getHistory()
      chart.setOption(this.getOptions(app.globalData.xdata, app.globalData.comData,app.globalData.healData));
      return chart;
    },

  //   获取历史接口
    


    
    getDate(){
        wx.request({
          url: 'https://api.inews.qq.com/newsqa/v1/query/inner/publish/modules/list?modules=statisGradeCityDetail,diseaseh5Shelf',
          success:(r)=>{
            //   console.log(r);
             let areaTree1 =r.data.data.diseaseh5Shelf
              let areaTree2 =r.data.data.diseaseh5Shelf.areaTree[0].children
             
              this.setData({
                 datalist:areaTree2,
                  time:areaTree1.lastUpdateTime,
                  confirm:areaTree1.chinaTotal.confirm,
                  dead:areaTree1.chinaTotal.dead,
				          nowSevere :areaTree1.chinaTotal.nowSevere,
				          nowConfirm : areaTree1.chinaTotal.nowConfirm,
				         suspect: areaTree1.chinaTotal.suspect,
				         noInfect :areaTree1.chinaTotal.noInfect,
				         importedCase : areaTree1.chinaTotal.importedCase,
				         heal : areaTree1.chinaTotal.heal,
				         addNowConfirm : areaTree1.chinaAdd.nowConfirm,
				         addConfirm : areaTree1.chinaAdd.confirm,
				         addDead : areaTree1.chinaAdd.dead,
				         addNowSevere : areaTree1.chinaAdd.nowSevere,
				         addSuspect :areaTree1.chinaAdd.suspect,
				         addNoInfect : areaTree1.chinaAdd.noInfect,
				         addImportedCase : areaTree1.chinaAdd.importedCase,
				         addHeal : areaTree1.chinaAdd.heal
              })
            
          }
        })
       
    },
    goDtail(e){
       // console.log(event)
       let i = e.currentTarget.dataset.index
      //  console.log(e)
      //  console.log(i) //索引
       // 跳转二级
       wx.navigateTo({
         url: '/pages/china/two/two?num='+i,
       })
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})